package com.example.wechathook.hook;

import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * 
 * 联系人界面获取信息
 * 
 * @author chencq
 *
 */
public class ContactHook extends BaseHook {

	@Override
	public void hook(XC_LoadPackage.LoadPackageParam lpp) {
		findAndHookMethod("com.tencent.mm.plugin.profile.ui.ContactInfoUI", lpp.classLoader, "onResume", Bundle.class,
				new XC_MethodHook() {
					@Override
					protected void afterHookedMethod(MethodHookParam param) throws Throwable {
						try {
							super.afterHookedMethod(param);

							final Activity activity = (Activity) param.thisObject;
							final ViewGroup contentView = (ViewGroup) activity.getWindow().getDecorView();

							int star = activity.getIntent().getIntExtra("x_action_star", 0);
							log("star:" + star);

							TextView textView = findTextView(contentView, "关注");
							if (textView != null) {
								int[] location = new int[2];
								textView.getLocationOnScreen(location);
								log("关注按钮的位置:" + location[0] + "," + location[1]);
							}

						} catch (Exception e) {
							log("contact hook exception");
						}
					}
				});
	}

}
